/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
// pkeydev.hpp - Pure virtual base class for keyboard devices
//
// Copyright (c) 1997-2008 Swell Software, Inc.
//              All Rights Reserved.
//
// Unauthorized redistribution of this source code, in whole or part,
// without the express written permission of Swell Software, Inc.
// is strictly prohibited.
//
// Notes:
//
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/

#ifndef _PKEYDEV_HPP_
#define _PKEYDEV_HPP_

#if defined(PEG_KEYBOARD_SUPPORT) && defined(PEG_KEYBOARD_INCLUDE)

/*--------------------------------------------------------------------------*/
// Keyboard defines
/*--------------------------------------------------------------------------*/
#ifndef PEG_KEYBOARD_POLL_DELAY
#define PEG_KEYBOARD_POLL_DELAY                     (1)
#endif

/*--------------------------------------------------------------------------*/
// If PC keyboard support is required, the driver operates a little different
/*--------------------------------------------------------------------------*/
#if defined(PEG_USB_KEYBOARD_SUPPORT) || defined(PEG_PCAT_KEYBOARD_SUPPORT)
#define PEG_PC_KEYBOARD_SUPPORT
#endif

/*--------------------------------------------------------------------------*/
// Single Key Structure
/*--------------------------------------------------------------------------*/
typedef struct
{
    PEGUSHORT NormalKey;
    PEGUSHORT ShiftKey;
} PEG_KEY_TABLE;

typedef struct
{
    PEG_KEY_TABLE   *pKeys;
    PEGBOOL         *pCurrentStates;
    PEGBOOL         *pPrevStates;
} PEG_KEY_DATA;

/*--------------------------------------------------------------------------*/
// If USB keyboard, extern the key table
/*--------------------------------------------------------------------------*/
#if defined(PEG_USB_KEYBOARD_SUPPORT)
extern PEG_KEY_TABLE PegUSBKeyTable[];
#define PEG_USB_KEYTABLE_LEN                        255
#endif

/*-------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------*/
class PegKeyboardDevice : public PegInputDevice
{
    public:
        PegKeyboardDevice(PEG_KEY_TABLE *pKeyTable, PEGINT NumKeys);
        virtual ~PegKeyboardDevice();

        virtual void Run(void);

       #if defined(PEG_USB_KEYBOARD_SUPPORT)
        virtual PEGBOOL SendUSBKeyMessage(PEGINT Index, PEGUSHORT UserData);
       #endif

    protected:
       #if !defined(PEG_USB_KEYBOARD_SUPPORT)
        virtual void    AllKeysUnpressed(void);
        virtual void    CheckSendMessage(void);
        virtual PEGBOOL DetectKeyPressed(void)= 0;
        virtual PEGBOOL GetKeyInfo(void) = 0;
       #endif
        virtual PEGBOOL Poll(void);

        PEG_KEY_DATA    mKeyData;
        PEGINT          mNumKeys;
        PEGBOOL         mCapLock;

};

/*-------------------------------------------------------------------------*/
// this function is declared here and defined in the driver source module
/*-------------------------------------------------------------------------*/
PegKeyboardDevice *CreatePegKeyboardDevice(void);

#endif  // PEG_KEYBOARD_SUPPORT
#endif  // _PKEYDEV_HPP_

